package com.ptu.spzx.manager.controller;


import com.github.pagehelper.PageInfo;
import com.ptu.spzx.manager.service.DeptService;
import com.ptu.spzx.manager.service.SysUserService;
import com.ptu.spzx.model.dto.system.AssginDeptDto;
import com.ptu.spzx.model.entity.system.SysDept;
import com.ptu.spzx.model.vo.common.Result;
import com.ptu.spzx.model.vo.common.ResultCodeEnum;
import com.ptu.spzx.model.vo.system.SysDeptVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/ac/system/sysDept")
public class SysDeptController {
    @Autowired
    private DeptService deptService;

    //删除部门接口
    @DeleteMapping("/removeById/{id}")
    public Result removeById(@PathVariable(value = "id") Long id){
        deptService.removeById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //更新部门接口
    @PutMapping("/update")
    public Result update(@RequestBody SysDept sysDept){
        deptService.updateDept(sysDept);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //部门的添加
    @PostMapping("/save")
    public Result save(@RequestBody SysDept sysDept){
        deptService.saveDept(sysDept);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //部门列表
    @GetMapping("/findNodes")
    public Result findNodes(){
        List<SysDeptVo> list=deptService.findNodes();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/findDeptAll")
    public List<SysDept> findDeptAll(){
        return deptService.findDeptAll();
    }

    @GetMapping("/findDept")
    public Result findDept(@RequestParam String keyWord){
        List<SysDeptVo> sysDeptVos=deptService.findDept(keyWord);
        return Result.build(sysDeptVos,ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/findDeptId")
    public Result findDeptId(@RequestParam Long id){
        return deptService.findDeptId(id);
    }

    @GetMapping("/findDeptFeign")
    public SysDept findDeptFeign(@RequestParam Long id){
        SysDept deptFeign = deptService.findDeptFeign(id);
        return deptFeign;
    }

    @GetMapping("/findByPage/{pageNum}/{pageSize}")
    public PageInfo<SysDept>  findByPage(@PathVariable("pageNum") Integer pageNum,
                             @PathVariable("pageSize") Integer pageSize,
                             @RequestParam (value = "keyWord",required = false) String keyWord,
                             @RequestParam (value = "classIds",required = false) List<Long> classIds ){
        PageInfo<SysDept> pageInfo = deptService.findByPage(pageNum,pageSize,keyWord,classIds);
        return pageInfo;
    }

    @GetMapping("/GetKeyWord")
    public Result GetKeyWord(@RequestParam String keyWord){
        List<String> deptName=deptService.GetKeyWord(keyWord);
        return Result.build(deptName,ResultCodeEnum.SUCCESS);
    }

}
